/**
 * 
 */
package com.fang.www.join.two.three;

import java.io.IOException;

import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

/**
 * @author 王刚
 *
 */
public class Reduce extends Reducer<UserKey, User, Text, NullWritable> {
	private User outputKey =new User();
	private Text output =new Text();
	private User locInfo = new User();
	@Override
	protected void setup(Reducer<UserKey, User, Text, NullWritable>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
	}

	@Override
	protected void reduce(UserKey key, Iterable<User> values, Reducer<UserKey, User, Text, NullWritable>.Context context)
			throws IOException, InterruptedException {
		// TODO Auto-generated method stub
		init();
		boolean flag = true;
		for(User value:values){
			if(flag){
				flag =false;
				locInfo.setLocalId(value.getLocalId());
				locInfo.setLocalName(value.getLocalName());
			}else{
				outputKey.setUsrId(value.getUsrId());
				outputKey.setUsrName(value.getUsrName());
				outputKey.setLocalId(value.getLocalId());
				outputKey.setLocalName(locInfo.getLocalName());
				output.set(outputKey.toString());
				context.write(output, NullWritable.get());
			}
			
		}
	}
	private void init(){
		outputKey.init1111();
		locInfo.init1111();
	}
}
